import pandas as pd
import numpy as np
# 读取CSV文件
df = pd.read_csv("new_file.csv")

# 将Q2列中的值1替换为"男"，值2替换为"女"
df['Q2'] = df['Q2'].replace({1: "男", 2: "女"})
# 根据条件替换Q3列的值
conditions = [
    (df['Q3'] == 1),
    (df['Q3'] == 2),
    (df['Q3'] == 3),
    (df['Q3'] == 4),
    (df['Q3'] == 5)
]
choices = ['20岁以下', '21岁—30岁', '31岁—40岁', '41岁—50岁', '51岁以上']
df['Q3'] = pd.Series(np.select(conditions, choices, default=df['Q3']))


# 根据条件替换Q4列的值
conditions = [
    (df['Q4'] == 1),
    (df['Q4'] == 2),
    (df['Q4'] == 3),
    (df['Q4'] == 4),
    (df['Q4'] == 5),
    (df['Q4'] == 6)
]
choices = ['初中以下', '职校', '大学专科', '大学本科', '硕士', '博士及以上']
df['Q4'] = pd.Series(np.select(conditions, choices, default=df['Q4']))


# 根据条件替换Q5列的值
conditions = [
    (df['Q5'] == 1),
    (df['Q5'] == 2),
    (df['Q5'] == 3),
    (df['Q5'] == 4),
    (df['Q5'] == 5),
    (df['Q5'] == 6),
    (df['Q5'] == 7),
    (df['Q5'] == 8),
    (df['Q5'] == 9),
    (df['Q5'] == 10),
    (df['Q5'] == 11),
    (df['Q5'] == 12),
    (df['Q5'] == 13)
]
choices = [
    '在校学生',
    '机关干部',
    '企业管理者',
    '普通职员',
    '专业人员',
    '普通工人',
    '商业服务业职工',
    '个体经营者',
    '自由职业者',
    '农林牧渔劳动者',
    '退休',
    '暂无职业',
    '其他职业人员'
]
df['Q5'] = pd.Series(np.select(conditions, choices, default=df['Q5']))

# 根据条件替换Q6列的值
conditions = [
    (df['Q6'] == 1),
    (df['Q6'] == 2),
    (df['Q6'] == 3),
    (df['Q6'] == 4),
    (df['Q6'] == 5)
]
choices = [
    '1500元',
    '1500元—2000元',
    '2000元—3000元',
    '3000元—5000元',
    '5000元以上'
]
df['Q6'] = pd.Series(np.select(conditions, choices, default=df['Q6']))

# 根据条件替换Q10列的值
df['Q10'] = df['Q10'].replace({
    1: '十分了解',
    2: '基本了解',
    3: '一知半解',
    4: '基本不了解',
    5: '没听说过'
})

# 根据条件替换Q11列的值
df['Q11'] = df['Q11'].replace({
    1: '有过',
    2: '没有过',
    3: '正在了解'
})

# 根据条件替换Q12列的值
df['Q12'] = df['Q12'].replace({
    1: '愿意',
    2: '可以尝试',
    3: '看别人使用情况',
    4: '不愿意'
})

# 根据条件替换Q13列的值
df['Q13'] = df['Q13'].replace({
    1: '意义重大',
    2: '毫无用途',
    3: '没有作用',
    4: '不了解'
})

# 根据条件替换Q14列的值
df['Q14'] = df['Q14'].replace({
    1: '非常愿意',
    2: '可以尝试',
    3: '看别人去不去',
    4: '不愿意'
})

# 保存DataFrame到CSV文件
df.to_csv("modified_csv_file.csv", index=False)

